package com.aabte.common.beans;

import com.aabte.common.constants.ErrorConstants;
import lombok.*;
import org.springframework.http.HttpStatus;

/**
 * @author Daniel
 */
@Data
@AllArgsConstructor
@Builder
public class ResponseBean<T extends Object> {
    private String trackId;
    private String innerCode;
    private String message;
    private T data;

    public ResponseBean() {
        this.innerCode = ErrorConstants.SUCCESS;
        this.message = HttpStatus.OK.getReasonPhrase();
    }

    public static ResponseBean success(Object data) {
        ResponseBean responseBean = new ResponseBean<>();
        responseBean.setData(data);
        return responseBean;
    }

    public static ResponseBean success(Object data, String msg) {
        ResponseBean responseBean = new ResponseBean<>();
        responseBean.setMessage(msg);
        responseBean.setData(data);
        return responseBean;
    }

    public static ResponseBean fail(String innerCode, String msg) {
        ResponseBean responseBean = new ResponseBean<>();
        responseBean.setInnerCode(innerCode);
        responseBean.setMessage(msg);
        responseBean.setData(null);
        return responseBean;
    }

    public static ResponseBean fail(String msg) {
        return fail(ErrorConstants.INTERNAL_SERVER_ERROR, msg);
    }

}
